﻿#if UNITY_EDITOR
using System;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay
{
    [ExecuteAlways]
    public class EditorSceneUpdate : MonoBehaviour
    {
        protected static EditorSceneUpdate instance;
        public Action OnUpdate;
        private void Awake()
        {
            this.Initialize();
        }

        private void OnEnable()
        {
            if (instance == null)
            {
                this.Initialize();
            }
        }

        private void Update()
        {
            if (instance == null)
            {
                this.Initialize();
            }
            this.OnUpdate?.Invoke();
        }
        
        public void Initialize()
        {
            instance = this;
            this.OnInitialize();
        }

        protected virtual void OnInitialize()
        {
        }
    }
}
#endif
